package project.movieMap.baseLib.beans;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import  com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.*;

import java.util.Date;
import java.util.HashSet;

@Data
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Comment {
    //实例化Comment必须有用户Id和评论内容和电影Id或地理位置Id
    @JsonCreator
    public Comment(@NonNull @JsonProperty("content") String content, @JsonProperty("fromUserId") int fromUserId) {
        this.content = content;
        this.fromUserId = fromUserId;
    }

    //评论Id
    private int Id;
    //评论内容
    @NonNull
    private String content;
    //评论时间,系统自动设定
    private Date date;
    //来自用户ID
    private int fromUserId;
    //对此评论的投票
    private int vote;
    //回复Id
    private HashSet<Integer> replyIds = new HashSet<>();

    public void addReply(int Id) {
        replyIds.add(Id);
    }
    public void removeReply(int Id) {
        replyIds.remove(Id);
    }
}
